float4x4 View;
float4x4 Projection;

float3 CameraPos;
float2 Scale;

texture diffuseTexture;

sampler diffuseSampler = sampler_state
{
	Texture = (diffuseTexture);
    MagFilter = Linear;
    MinFilter = Anisotropic;
    MipFilter = Linear;
    MaxAnisotropy = 2;
};

// TODO: add effect parameters here.

struct VertexShaderInput
{
    float3 Position : POSITION0;
	float2 UV : TEXCOORD0;

    // TODO: add input channels such as texture
    // coordinates and vertex colors here.
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
	float2 UV : TEXCOORD0;

    // TODO: add vertex shader outputs such as colors and texture
    // coordinates here. These values will automatically be interpolated
    // over the triangle, and provided as input to your pixel shader.
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

	//float3 localZ = normalize(input.Position-CameraPos);
	float3 localZ = normalize(CameraPos);
	float3 localX = normalize(cross(localZ, float3(0, 1, 0)));
	float3 localY = cross(localZ, localX);

	float2 ScaledUV=((input.UV-float2(0.5f, 0.5f))*2)*Scale;

	float3 Position = input.Position+(ScaledUV.x*localX)+(ScaledUV.y*localY);

    float4 viewPosition = mul(float4(Position, 1.0f), View);
	output.Position = mul(viewPosition, Projection);
	output.UV=input.UV;
    // TODO: add your vertex shader code here.

    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    // TODO: add your pixel shader code here.
	return tex2D(diffuseSampler, input.UV);
}

technique Technique1
{
    pass Pass1
    {
        // TODO: set renderstates here.

        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}
